import java.io.OutputStream;
import java.util.Enumeration;

import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;

public class SimpleWrite {
	static Enumeration portList;
	static CommPortIdentifier portId;
	static String messageString = "我日你B 51730479!";
	static SerialPort serialPort;
	static OutputStream outputStream;

	public static void main(String[] args) {
		portList = CommPortIdentifier.getPortIdentifiers();
		while (portList.hasMoreElements()) {
			portId = (CommPortIdentifier) portList.nextElement();
			if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
				if (portId.getName().equals("COM1")) {
					// if (portId.getName().equals("/dev/term/a")) {
					try {
						serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000);
						outputStream = serialPort.getOutputStream();
						serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
						while(true){
							Thread.sleep(1000);
							outputStream.write(messageString.getBytes());
						}
					} catch (Exception e) {
					}
				}
			}
		}
	}
}